package com.gimi.cloud.bbp.manage.consumer.service.prod.impl;

import com.gimi.cloud.bbp.common.enums.ResponseCodeEnum;
import com.gimi.cloud.bbp.common.exception.MsgException;
import com.gimi.cloud.bbp.common.utils.JsonUtil;
import com.gimi.cloud.bbp.common.utils.StringUtil;
import com.gimi.cloud.bbp.common.utils.reqhead.Response;
import com.gimi.cloud.bbp.common.utils.reqhead.Util;
import com.gimi.cloud.bbp.dto.prod.EcProdCatModelDTO;
import com.gimi.cloud.bbp.dto.prod.EcProdCatModelValueDTO;
import com.gimi.cloud.bbp.manage.consumer.feign.ProdCatModelFeignService;
import com.gimi.cloud.bbp.manage.consumer.service.prod.ProdCatModelService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @auther loongs
 * @date 2017/12/18  15:57
 */
@Service
public class ProdCatModelServiceImpl implements ProdCatModelService {

    private static final Logger logger = LoggerFactory.getLogger(ProdCatModelServiceImpl.class);
    private ProdCatModelFeignService prodCatModelFeignService;
    @Autowired
    public ProdCatModelServiceImpl(ProdCatModelFeignService prodCatModelFeignService) {
        this.prodCatModelFeignService = prodCatModelFeignService;
    }

    @Override
    public Response getProdCatModelList(String requestBody, HttpServletRequest request, HttpServletResponse response) throws MsgException{
        logger.info("请求参数===>" + JsonUtil.replaceNow(requestBody));
        EcProdCatModelDTO prodCatModelDTO = JsonUtil.jsonToBean(requestBody,EcProdCatModelDTO.class);
        return prodCatModelFeignService.getProdCatModelList(prodCatModelDTO);
    }

    @Override
    public Response addProdCatModel(String requestBody, HttpServletRequest request, HttpServletResponse response) throws MsgException {
        logger.info("请求参数===>" + JsonUtil.replaceNow(requestBody));
        EcProdCatModelDTO prodCatModelDTO = JsonUtil.jsonToBean(requestBody,EcProdCatModelDTO.class);
        if(StringUtil.isBlank(prodCatModelDTO.getProdCatId())||StringUtil.isBlank(prodCatModelDTO.getProdPropName())||
               StringUtil.isBlank(prodCatModelDTO.getSeq())){
            throw new MsgException(ResponseCodeEnum.PARAMETER_ERROR);
        }
        return prodCatModelFeignService.addProdCatModel(prodCatModelDTO);
    }

    @Override
    public Response editProdCatModel(String requestBody, HttpServletRequest request, HttpServletResponse response) throws MsgException {
        logger.info("请求参数===>" + JsonUtil.replaceNow(requestBody));
        EcProdCatModelDTO prodCatModelDTO = JsonUtil.jsonToBean(requestBody,EcProdCatModelDTO.class);
        if(StringUtil.isBlank(prodCatModelDTO.getProdCatId())||StringUtil.isBlank(prodCatModelDTO.getSeq())
               |StringUtil.isBlank(prodCatModelDTO.getModelId())||StringUtil.isBlank(prodCatModelDTO.getProdPropName())){
            throw new MsgException(ResponseCodeEnum.PARAMETER_ERROR);
        }
        return prodCatModelFeignService.editProdCatModel(prodCatModelDTO);
    }

    @Override
    public Response gotoEditProdCatModel(String requestBody, HttpServletRequest request, HttpServletResponse response) throws MsgException {
        logger.info("请求参数===>" + JsonUtil.replaceNow(requestBody));
        EcProdCatModelDTO prodCatModelDTO = JsonUtil.jsonToBean(requestBody,EcProdCatModelDTO.class);
        if(StringUtil.isBlank(prodCatModelDTO.getModelId())){
            throw new MsgException(ResponseCodeEnum.PARAMETER_ERROR);
        }
        return prodCatModelFeignService.gotoEditProdCatModel(prodCatModelDTO);
    }

    @Override
    public Response deleteProdCatModel(String requestBody, HttpServletRequest request, HttpServletResponse response) throws MsgException {
        logger.info("请求参数===>" + JsonUtil.replaceNow(requestBody));
        EcProdCatModelDTO prodCatModelDTO = JsonUtil.jsonToBean(requestBody,EcProdCatModelDTO.class);
        if(StringUtil.isBlank(prodCatModelDTO.getModelId())){
            throw new MsgException(ResponseCodeEnum.PARAMETER_ERROR);
        }
        return prodCatModelFeignService.deleteProdCatModel(prodCatModelDTO);
    }

    @Override
    public Response realDeleteProdCatModel(String requestBody, HttpServletRequest request, HttpServletResponse response) throws MsgException {
        logger.info("请求参数===>" + JsonUtil.replaceNow(requestBody));
        EcProdCatModelDTO prodCatModelDTO = JsonUtil.jsonToBean(requestBody,EcProdCatModelDTO.class);
        if(StringUtil.isBlank(prodCatModelDTO.getModelId())){
            throw new MsgException(ResponseCodeEnum.PARAMETER_ERROR);
        }
        return prodCatModelFeignService.realDeleteProdCatModel(prodCatModelDTO);
    }

    @Override
    public Response getProdCatModelValueList(String requestBody, HttpServletRequest request, HttpServletResponse response) throws MsgException {
        logger.info("请求参数===>" + JsonUtil.replaceNow(requestBody));
        EcProdCatModelValueDTO prodCatModelValueDTO = JsonUtil.jsonToBean(requestBody, EcProdCatModelValueDTO.class);
        if(StringUtil.isBlank(prodCatModelValueDTO.getModelId())){
            throw new MsgException(ResponseCodeEnum.PARAMETER_ERROR);
        }
        return prodCatModelFeignService.getProdCatModelValueList(prodCatModelValueDTO);
    }

    @Override
    public Response addProdCatModelValue(String requestBody, HttpServletRequest request, HttpServletResponse response) throws MsgException {
        logger.info("请求参数===>" + JsonUtil.replaceNow(requestBody));
        EcProdCatModelValueDTO prodCatModelValueDTO = JsonUtil.jsonToBean(requestBody, EcProdCatModelValueDTO.class);
        if(StringUtil.isBlank(prodCatModelValueDTO.getModelId())||StringUtil.isBlank(prodCatModelValueDTO.getIsImg())||
                StringUtil.isBlank(prodCatModelValueDTO.getModelValue())){
            throw new MsgException(ResponseCodeEnum.PARAMETER_ERROR);
        }
        return prodCatModelFeignService.addProdCatModelValue(prodCatModelValueDTO);
    }

    @Override
    public Response gotoEditProdCatModelValue(String requestBody, HttpServletRequest request, HttpServletResponse response) throws MsgException {
        logger.info("请求参数===>" + JsonUtil.replaceNow(requestBody));
        EcProdCatModelValueDTO prodCatModelValueDTO = JsonUtil.jsonToBean(requestBody, EcProdCatModelValueDTO.class);
        if(StringUtil.isBlank(prodCatModelValueDTO.getCmId())){
            throw new MsgException(ResponseCodeEnum.PARAMETER_ERROR);
        }
        return prodCatModelFeignService.gotoEditProdCatModelValue(prodCatModelValueDTO);
    }

    @Override
    public Response editProdCatModelValue(String requestBody, HttpServletRequest request, HttpServletResponse response) throws MsgException {
        logger.info("请求参数===>" + JsonUtil.replaceNow(requestBody));
        EcProdCatModelValueDTO prodCatModelValueDTO = JsonUtil.jsonToBean(requestBody, EcProdCatModelValueDTO.class);
        if(StringUtil.isBlank(prodCatModelValueDTO.getModelId())||StringUtil.isBlank(prodCatModelValueDTO.getIsImg())||
                StringUtil.isBlank(prodCatModelValueDTO.getModelValue())||StringUtil.isBlank(prodCatModelValueDTO.getCmId())){
            throw new MsgException(ResponseCodeEnum.PARAMETER_ERROR);
        }
        return prodCatModelFeignService.editProdCatModelValue(prodCatModelValueDTO);
    }

    @Override
    public Response realDeleteProdCatModelValue(String requestBody, HttpServletRequest request, HttpServletResponse response) throws MsgException {
        logger.info("请求参数===>" + JsonUtil.replaceNow(requestBody));
        EcProdCatModelValueDTO prodCatModelValueDTO = JsonUtil.jsonToBean(requestBody, EcProdCatModelValueDTO.class);
        if(StringUtil.isBlank(prodCatModelValueDTO.getCmId())){
            throw new MsgException(ResponseCodeEnum.PARAMETER_ERROR);
        }
        return prodCatModelFeignService.realDeleteProdCatModelValue(prodCatModelValueDTO);
    }


}
